// 观察者模式 示例代码
interface ISubject {
    void Register(IObserver o);
    void Remove(IObserver o);
    void Notify();
}

interface IObserver {
    void Update(string message);
}

class Subject : ISubject {
    List<IObserver> _observers = new();

    public void Register(IObserver observer) => _observers.Add(observer);

    public void Remove(IObserver observer) => _observers.Remove(observer);

    public void Notify() =>
        foreach (var observer in _observers) observer.Update("Something happened");
}

class Observer : IObserver {
    public void Update(string message) => Console.WriteLine(message);
}